const download = require('download-git-repo')
const ora = require('ora')
const chalk = require('chalk')

const downloadFun = function (url, name) {
  const spinner = ora().start()
  spinner.text = '正在下载模板'
  download(`direct:${url}#main`, name, { clone: true }, function (err) {
    if (err) {
      spinner.fail('下载失败')
      process.exit(1)
    } else {
      spinner.succeed('Download Success, Please run')
      console.log(chalk.green('cd ' + name))
      console.log(chalk.green('npm install'))
      console.log(chalk.green('npm run dev'))
    }
  })
}

module.exports = downloadFun